package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.First;
import com.example.entity.Income;
import com.example.mapper.FirstMapper;
import com.example.mapper.IncomeMapper;
import com.example.service.IFirstService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-11-11
 */
@Service
@RequiredArgsConstructor
public class FirstServiceImpl extends ServiceImpl<FirstMapper, First> implements IFirstService {

    private final FirstMapper firstMapper;

    private final IncomeMapper incomeMapper;

    @Override
    public void delete(List<Long> ids) throws Exception {
        for (Long id : ids) {
            List<Income> incomes = incomeMapper.selectList(new LambdaQueryWrapper<Income>()
                    .eq(Income::getTypeKey, id));
            if (incomes != null && incomes.size() > 0){
                throw new Exception("标签仍存在绑定收入数据，不能批量删除");
            }
            firstMapper.deleteById(id);
        }
    }
}
